package com.ipc.app.web.controller;

import java.io.UnsupportedEncodingException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ipc.app.biz.InformationBiz;
import com.ipc.app.model.Information;
import com.ipc.app.model.Paginator;

@Controller
@RequestMapping(value = "/jsp/cityInformationView.do")
public class CityInformationAction {

	@Autowired
	private InformationBiz informationBiz;

	@RequestMapping(method = RequestMethod.GET)
	public String cityInformationView(ModelMap model, String city, String index) {
		if (null == index) {
			index = "0";
		}

		try {
			Paginator<Information> informations = informationBiz
					.getInformationByCity(new String(city
							.getBytes("ISO-8859-1"), "UTF-8"), null, Integer
							.valueOf(index));
			model.addAttribute("city", new String(city.getBytes("ISO-8859-1"),
					"UTF-8"));
			model.addAttribute("informations", informations);
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return "cityInformation";
	}
}
